#include <iostream>
#include <cstring>

using namespace std;
// #define ONLINE_JUDGE
const int N = 210;

int s[N];
int f[N][N];

int main() {

    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);
	cin.tie(0);

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {    
        cin >> s[i]; 
        s[n+i] = s[i];
    }


    // 区间DP枚举套路，长度+左端点
    for(int len = 3; len <= n + 1; len++) // len表示[i,j]的元素个数
    {
        for(int l = 1; l +len-1 <= n << 1; l++){
            int r = l + len - 1; // 计算右端点
            for(int k = l + 1; k < r; k++) //
                f[l][r] = max(f[l][r], f[l][k] + f[k][r] + s[l] * s[k] * s[r]); // 
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) ans = max(ans, f[i][i+n]);
    cout << ans << endl;

    return 0;
}
